import Opt from '@/components/dt/info/Opt.js'
import nameOpt from '@/biz/option/name.js'

class Column extends Opt {
  constructor(obj) {
    super()
    this.isEdit = obj.isEdit
    this.tabType = obj.tabType
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    console.log(this)
    this.all = [
      {
        title: '内容',
        field: 'content',
        minWidth: 180,
        align: 'center'
      },
      {
        title: '数量',
        field: 'num',
        minWidth: 180,
        align: 'center'
      },
      {
        title: '存档管理人',
        field: 'manager',
        minWidth: 180,
        align: 'center',
        cell: (row) => {
          if (this.isEdit) {
            return {
              edit: nameOpt.createPeople({
                from: (info) => {
                  return info.manager?.split('(')[1].split(')')[0]
                },
                to: (v) => {
                  return {
                    manager: v.userName && v.workNo ? `${v.userName}(${v.workNo})` : ''
                  }
                }
              })
            }
          } else {
            return { text: {} }
          }
        }
      },
      {
        title: '备注',
        field: 'remark',
        minWidth: 180,
        align: 'center',
        cell: (row) => {
          if (this.isEdit && this.tabType == 0) {
            return { edit: { input: { maxlength: 200 } } }
          } else {
            return { text: {} }
          }
        }
      }
    ]
  }
}

export default Column
